import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:flutter_appdemo02/list/Test.dart';

class HttpPage extends StatefulWidget {
  @override
  _HttpPageState createState() => _HttpPageState();
}

class _HttpPageState extends State<HttpPage> {

  List _list = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _getDate();
  }

  _getDate() async{
    var url = "http://47.254.47.196:7010/getSlideUserList.do";
    var response = await http.post(url,body: {'sex':'1', 'page':'1'});

    Test t = new Test(response.body);
    List<Test1> list = t.list;
    _list = list;
    for(int i=0;i<list.length;i++){
      print('name:'+list[i].nickname);
      print("age-----"+list[i].age.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Http测试"),
      ),
      body: Column(
        children: <Widget>[
          RaisedButton(
            child: Text("Post请求数据"),
            onPressed: () {
              _getDate();
              setState(() {

              });
            },
          ),
          this._list.length>0?ListView.builder(
            itemBuilder: (BuildContext context,int index) {
              return ListTile(
                title: Text("${_list[index]["age"].toString()}"),
              );
            },
          ):Text("加载中")
        ],
      ),
    );
  }
}

